<template>
    <div class="content">
        <div class="grade-top">
            <span>考试次数:{{params.total}}</span>
            <span>平均分:{{kSScore.avg}}</span>
            <span>权重:{{kSScore.weight}}</span>
            <span>计算得分:{{kSScore.scores}}</span>
        </div>
        <div class="clearfix">
            <Form class="f-fl" inline :label-width="5">
                <FormItem>
                    <Input
                        v-model="params.examName"
                        placeholder="考试名称"
                    ></Input>
                </FormItem>
                <FormItem>
                    <Button type="primary" @click="search">搜索</Button>
                </FormItem>
                <FormItem>
                    <Button @click="clearSearch">清空</Button>
                </FormItem>
            </Form>

        </div>
        <Table :data="list" :columns="columns" border align="center">
            <template slot-scope="{ row }" slot="action">
                <div class="table-action">
                    <Button :disabled ="row.status==1||row.status==2" type="text" @click="ckStart(row)">查看试卷</Button>
                </div>
            </template>
        </Table>
        <Pagination
            :pageSize.sync="params.pageSize"
            :current.sync="params.pageNum"
            :total="params.total"
            @change="queryList"
        />
    </div>
</template>
<script>
import { viewExam, examGradeList, stuGrade } from '@/api/studentExam'

export default {
    inject: ['nextPageReload'],
    data () {
        return {
            roleType: '',
            schoolList: [],
            params: {
                examName: '',
                pageNum: 1,
                pageSize: 10,
                total: 0
            },
            kSScore: [],
            list: [],
            columns: Object.freeze([
                { title: '序号', type: 'index', align: 'center', width: 80 },
                { title: '考试名称', key: 'examName', align: 'center', width: 200 },
                { title: '考试起止时间', key: 'time', align: 'center' },
                { title: '题量', key: 'num', align: 'center' },
                { title: '客观题得分', key: 'objectiveScore', align: 'center' },
                { title: '主观题得分', key: 'subjectiveScore', align: 'center' },
                { title: '总得分', key: 'scores', align: 'center' },
                { title: '操作', slot: 'action', align: 'center', width: 160 }
            ])
        }
    },
    mounted () {
        this.queryList()
        this.getStuGrade()
    },
    methods: {
        search () {
            this.params.pageNum = 1
            this.queryList()
        },
        getStuGrade () {
            stuGrade({}).then(res => {
                this.gradeList = res.data.data
                this.kSScore = this.gradeList[0]
            })
        },
        ckStart (row) {
            viewExam({ examId: row.examId }).then(res => {
                if (res.data.code != '0000') {
                    this.$Message.error(res.data.msg)
                    return
                }
                this.nextPageReload()
                this.$router.push({
                    name: 'studentExam',
                    query: {
                        id: row.examId,
                        endTime: row.endTime,
                        type: 2,
                        examName: row.examName
                    }
                })
            })
        },
        clearSearch () {
            this.queryList()
        },
        queryList () {
            let params = {
                examName: this.params.examName,
                pageNum: this.params.pageNum,
                pageSize: this.params.pageSize
            }
            examGradeList(params).then(res => {
                if (res.data.code != '0000') {
                    this.$Message(res.data.data)
                    return
                }
                this.list = res.data.data.list
                this.params.total = res.data.data.total
            })
        }
    }
}
</script>
<style lang="less" scoped>
.grade-top{
    height:40px;
    line-height: 40px;
    span{
        margin-right:50px;
    }
}
</style>
